-
Notifications
You must be signed in to change notification settings - Fork 380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Next Gen GitHub Tag Action #252
Changes from all commits
221b1b5
57c2963
8ebc2ab
8ee5792
ed87534
fd09583
7369c9a
34c6984
f368c74
237a5ff
92ea001
19d6f3e
9d5c351
b2f1d5a
4b84757
f2525ab
c00c475
441a86c
6b18d80
387b939
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,42 @@ | ||
### Pull Request Title | ||
|
||
<!--- Provide a general summary of your changes in the Title above --> | ||
<!--- See [CONTRIBUTING.md](CONTRIBUTING.md) and [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md). --> | ||
# Summary of changes | ||
|
||
<!--- Describe your changes --> | ||
### Checklist | ||
|
||
- [ ] I have read and followed the [CONTRIBUTING.md](CONTRIBUTING.md) and [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md) guidelines. | ||
|
||
### Summary of Changes | ||
|
||
<!--- Briefly describe your changes --> | ||
|
||
- Change 1 | ||
- Change 2 | ||
- ... | ||
|
||
### Breaking Changes | ||
|
||
<!--- Are there any breaking changes in this PR? If so, describe them. --> | ||
|
||
- [ ] Yes | ||
- [ ] No | ||
|
||
### How Changes Have Been Tested | ||
|
||
## Breaking Changes | ||
<!--- Please describe in detail how you tested your changes. Include details of your testing environment, and the tests you ran to see how your change affects other areas of the code, etc. --> | ||
|
||
Do any of the included changes break current behaviour or configuration? | ||
1. Test A | ||
2. Test B | ||
3. ... | ||
|
||
(**YES** / NO) | ||
### Known Issues or Limitations | ||
|
||
## How changes have been tested | ||
<!--- List any unknowns, limitations or issues with your changes. --> | ||
|
||
- | ||
1. Issue A | ||
2. Limitation B | ||
3. ... | ||
|
||
## List any unknowns | ||
### Additional Notes (optional) | ||
|
||
- | ||
<!--- Provide any additional context, screenshots, or other relevant information. --> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,47 +7,45 @@ on: | |
branches: | ||
- master | ||
paths: | ||
- 'entrypoint.sh' | ||
- 'action.yml' | ||
- 'Dockerfile' | ||
- "entrypoint.sh" | ||
- "action.yml" | ||
- "Dockerfile" | ||
|
||
jobs: | ||
bump-version: | ||
if: github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: '0' | ||
fetch-depth: "0" | ||
|
||
- name: version-tag | ||
- name: Bump version tag | ||
id: tag | ||
uses: anothrNick/github-tag-action@master # if we use 1 there is a too-be-fixed bug https://github.com/anothrNick/github-tag-action/actions/runs/3139501775/jobs/5099976842#step:1:35 as alternative we could use v1 | ||
uses: anothrNick/github-tag-action@master | ||
env: | ||
VERBOSE: true | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
# auto releases is not working atm and is deleting releases due branch tags | ||
- name: automatic-draft-release | ||
- name: Create automatic draft release | ||
uses: marvinpinto/[email protected] | ||
with: | ||
draft: true | ||
repo_token: ${{ secrets.GITHUB_TOKEN }} | ||
title: "${{ steps.tag.outputs.tag }}: [title-edit-me] by:${{ github.actor }}" | ||
automatic_release_tag: ${{ steps.tag.outputs.new_tag }} | ||
|
||
- name: version-tag-major | ||
- name: Update major version tag | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
git fetch --tags | ||
tagFmt="^v?[0-9]+\.[0-9]+\.[0-9]+$" | ||
tag="$(git for-each-ref --sort=-v:refname --format '%(refname:lstrip=2)' | grep -E "$tagFmt" | head -n 1)" | ||
[[ "$tag" =~ ^([0-9]+) ]] # use ^(v[0-9]+) for vX | ||
[[ "$tag" =~ ^([0-9]+) ]] | ||
major=${BASH_REMATCH[1]} | ||
# update major tag | ||
git tag -f "$major" | ||
git push -f origin "$major" | ||
# add vX as 1 is linked to short sha bug https://github.com/anothrNick/github-tag-action/actions/runs/3139501775/jobs/5099976842#step:1:35 | ||
git tag -f "v$major" | ||
git push -f origin "v$major" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
name: Create and publish a Container Image | ||
on: | ||
schedule: | ||
- cron: "41 15 * * *" | ||
push: | ||
branches: ["master", "main"] | ||
# Publish semver tags as releases. | ||
tags: ["v*.*.*"] | ||
pull_request: | ||
branches: ["master", "main"] | ||
env: | ||
REGISTRY: ghcr.io | ||
IMAGE_NAME: ${{ github.repository }} | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
id-token: write | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
- name: Install cosign | ||
if: github.event_name != 'pull_request' | ||
uses: sigstore/[email protected] | ||
with: | ||
cosign-release: "v2.0.0" | ||
- name: Setup Docker buildx | ||
uses: docker/setup-buildx-action@v2 | ||
- name: Log into registry ${{ env.REGISTRY }} | ||
if: github.event_name != 'pull_request' | ||
uses: docker/[email protected] | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Extract Docker metadata | ||
id: meta | ||
uses: docker/[email protected] | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
- name: Build and push Docker image | ||
id: build-and-push | ||
uses: docker/[email protected] | ||
with: | ||
platforms: linux/amd64 | ||
context: . | ||
push: ${{ github.event_name != 'pull_request' }} | ||
tags: ${{ steps.meta.outputs.tags }}, | ||
labels: ${{ steps.meta.outputs.labels }} | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max | ||
- name: Sign the published Docker image | ||
if: ${{ github.event_name != 'pull_request' }} | ||
env: | ||
COSIGN_EXPERIMENTAL: "true" | ||
run: echo "${{ steps.meta.outputs.tags }}" | xargs -I {} cosign sign -y {}@${{ steps.build-and-push.outputs.digest }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/bin/bash | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Just so it's portable. |
||
|
||
set -euo pipefail | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A nice little addition I like to add to shell scripts to add set -x only if you're debugging: DEBUG=${DEBUG:-false}
function debug() {
echo "Debug mode enabled" >>"$GITHUB_STEP_SUMMARY"
# Print all environment variables
env | sort >>"$GITHUB_STEP_SUMMARY"
echo -e "\n" >>"$GITHUB_STEP_SUMMARY"
set -x
}
if [[ $DEBUG == 'true' ]]; then
debug
fi |
||
|
||
MAIN_OUTPUT_TAG=$1 | ||
MAIN_OUTPUT_NEWTAG=$2 | ||
MAIN_OUTPUT_PART=$3 | ||
PRE_OUTPUT_TAG=$4 | ||
PRE_OUTPUT_NEWTAG=$5 | ||
PRE_OUTPUT_PART=$6 | ||
|
||
echo "Outputs from running the action:" >>"$GITHUB_STEP_SUMMARY" | ||
echo "MAIN Tag: $MAIN_OUTPUT_TAG" >>"$GITHUB_STEP_SUMMARY" | ||
echo "MAIN New tag: $MAIN_OUTPUT_NEWTAG" >>"$GITHUB_STEP_SUMMARY" | ||
echo "MAIN Part: $MAIN_OUTPUT_PART" >>"$GITHUB_STEP_SUMMARY" | ||
echo "PRE Tag: $PRE_OUTPUT_TAG" >>"$GITHUB_STEP_SUMMARY" | ||
echo "PRE New tag: $PRE_OUTPUT_NEWTAG" >>"$GITHUB_STEP_SUMMARY" | ||
echo "PRE Part: $PRE_OUTPUT_PART" >>"$GITHUB_STEP_SUMMARY" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A little trick with this to make it render in a nice table can be something like this: OUTPUT_SUMMARY="\n
| Output | Value | \n
| ------------ | --------------------- | \n
| | | \n
| MAIN Tag | ${MAIN_OUTPUT_TAG} | \n
| MAIN New tag | ${MAIN_OUTPUT_NEWTAG} | \n
| MAIN Part | ${MAIN_OUTPUT_PART} | \n
| PRE Tag | ${PRE_OUTPUT_TAG} | \n
| PRE New tag | ${PRE_OUTPUT_NEWTAG} | \n
| PRE Part | ${PRE_OUTPUT_PART} | \n
"
echo -e "$OUTPUT_SUMMARY" >>"$GITHUB_STEP_SUMMARY" |
||
|
||
verlte() { | ||
[ "$1" = "$(echo -e "$1\n$2" | sort -V | head -n1)" ] | ||
} | ||
verlt() { | ||
[ "$1" = "$2" ] && return 1 || verlte "$1" "$2" | ||
} | ||
|
||
main="$(verlt "$MAIN_OUTPUT_TAG" "$MAIN_OUTPUT_NEWTAG" && true || false)" | ||
pre="$(verlt "$PRE_OUTPUT_TAG" "$PRE_OUTPUT_NEWTAG" && true || false)" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It feels weird to have double quotes inside a double quoted string but it does seem to work on my machine as well 🤷 |
||
|
||
if $main && $pre; then | ||
echo "The tags were created correctly" >>"$GITHUB_STEP_SUMMARY" | ||
else | ||
echo "Tags not created correctly" >>"$GITHUB_STEP_SUMMARY" | ||
exit 1 | ||
fi | ||
|
||
# Test for #none bump | ||
if [[ $MAIN_OUTPUT_PART == "none" ]]; then | ||
if [[ $MAIN_OUTPUT_TAG == "$MAIN_OUTPUT_NEWTAG" ]]; then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the variable on the left of the comparison should be quoted as well. |
||
echo "None bump test passed" >>"$GITHUB_STEP_SUMMARY" | ||
else | ||
echo "None bump test failed" >>"$GITHUB_STEP_SUMMARY" | ||
exit 1 | ||
fi | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh nice! Great to see some security improvements!