Dynamically linking Github objects is immensely useful. This table contains some good examples:
Linking Github ObjectsReference | Link Composition |
---|---|
User | https://github.com/${{ github.actor }} |
User Avatar |
https://github.com/${{ github.actor }}.png
Accepts the 'size' query string with av value up to '460' |
Actions URL | ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|${{ github.workflow }} |
Commit SHA | ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}|${{ github.sha }} |
💡 Note that these can be constructed with Github Variables as well, if used within a run context.
Github Actions DOES NOT have a great way to avoid triggering on closed but not merged PRs. This example demonstrates their solution. Note that making the remaining jobs depend on init will prevent them from running in a slightly more elegant way. Unfortunately this still results in a Run entry by the Github Action, though the jobs will be skipped.
Skipped Run
Skipped Job
Actions Workflow Snippet
name: Build
on:
pull_request:
branches:
- main
types:
- closed
jobs:
init:
if: github.event.pull_request.merged == true
name: Initialize
...
name: Build
on:
pull_request:
branches:
- main
types:
- closed
jobs:
init:
if: github.event.pull_request.merged == true
name: Initialize
runs-on: ubuntu-latest
steps:
- name: Checkout Source
uses: actions/checkout@v4
with:
lfs: true
fetch-depth: 0
- name: Initialize
id: init
run: |
REPOSITORY=${PWD##*/}
echo "REPOSITORY=$REPOSITORY" >> $GITHUB_OUTPUT
#PRODUCT=$(cut -d- -f3- <<< ${PWD##*/})
PRODUCT="recreation-secrets-management"
echo "PRODUCT=$PRODUCT" >> $GITHUB_OUTPUT
PRODUCT_LOWER=${PRODUCT,,}
echo "PRODUCT_LOWER=$PRODUCT_LOWER" >> $GITHUB_OUTPUT
- name: GitOps Automatic Versioning
id: gitops-autover
uses: AlexAtkinson/github-action-gitops-autover@0.3.0
outputs:
REPOSITORY: ${{ steps.init.outputs.REPOSITORY }}
PRODUCT: ${{ steps.init.outputs.PRODUCT }}
PRODUCT_LOWER: ${{ steps.init.outputs.PRODUCT_LOWER }}
NEW_VERSION: ${{ steps.gitops-autover.outputs.new-version }}
PREVIOUS_VERSION: ${{ steps.gitops-autover.outputs.previous-version }}
github-release:
name: Github Release
needs: [init]
runs-on: ubuntu-latest
steps:
- name: GitHub Release
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
name: "${{ needs.init.outputs.PRODUCT }} ${{ needs.init.outputs.NEW_VERSION }}"
tag_name: "apps_${{ needs.init.outputs.NEW_VERSION }}"
prerelease: false
generate_release_notes: true