Update Release workflow to generate ghcr images#175
Merged
Conversation
Signed-off-by: Pramod Bindal <prbindal@redhat.com>
Comment on lines
+9
to
+69
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: checkout the source code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - uses: actions/setup-go@v5 | ||
| with: | ||
| go-version: ^1.23 | ||
|
|
||
| - name: cache go modules | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: ~/go/pkg/mod | ||
| key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-go- | ||
|
|
||
| - uses: docker/login-action@v3 | ||
| with: | ||
| registry: ghcr.io | ||
| username: ${{ github.actor }} | ||
| password: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - uses: ko-build/setup-ko@v0.8 | ||
|
|
||
| - name: build and push container images | ||
| run: ./hack/build.sh | ||
| env: | ||
| KO_PUSH: "true" | ||
| KO_DOCKER_REPO: "ghcr.io/${{ github.repository }}" | ||
|
|
||
| - name: generate a build timestamp and sha256sum files | ||
| run: | | ||
| cd builds | ||
| echo `date -u +'%Y%m%d%H%M%S'` > ./build_timestamp.txt | ||
| echo `date -u +'%Y-%m-%dT%H:%M:%S%:z'` >> ./build_timestamp.txt | ||
| sha256sum *.yaml > ./SHA256SUMS.txt | ||
|
|
||
| - name: update release notes and executables | ||
| if: startsWith(github.ref, 'refs/tags/') # executes only for new release | ||
| uses: softprops/action-gh-release@v2 | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| with: | ||
| files: | | ||
| builds/*.yaml | ||
| builds/build_timestamp.txt | ||
| builds/SHA256SUMS.txt | ||
|
|
||
| - name: Update executables for main branch changes | ||
| if: startsWith(github.ref, 'refs/heads/main') # executes only for changes in main | ||
| uses: "marvinpinto/action-automatic-releases@latest" | ||
| with: | ||
| repo_token: "${{ secrets.GITHUB_TOKEN }}" | ||
| automatic_release_tag: main-devel | ||
| prerelease: true | ||
| title: "Development Build - main branch" | ||
| files: | | ||
| builds/*.yaml | ||
| builds/build_timestamp.txt | ||
| builds/SHA256SUMS.txt No newline at end of file |
Check warning
Code scanning / CodeQL
Workflow does not contain permissions Medium
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 11 months ago
To fix the issue, we need to add a permissions block to the workflow. This block should specify the minimal permissions required for the workflow to function correctly. Based on the steps in the workflow:
contents: readis required for checking out the source code and caching Go modules.packages: writeis required for Docker login and pushing container images.issues: writeandpull-requests: writeare not needed, as the workflow does not interact with issues or pull requests.contents: writeis required for updating release notes and executables.
The permissions block can be added at the root level of the workflow to apply to all jobs, or it can be added to individual jobs. In this case, adding it at the root level is more concise and appropriate.
Suggested changeset
1
.github/workflows/build_and_publish.yaml
| @@ -1,2 +1,5 @@ | ||
| name: build and publish | ||
| permissions: | ||
| contents: read | ||
| packages: write | ||
| on: |
Copilot is powered by AI and may make mistakes. Always verify output.
Unable to commit as this autofix suggestion is now outdated
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
Submitter Checklist
These are the criteria that every PR should meet, please check them off as you
review them:
make test lintbefore submitting a PRRelease Notes