PR actions #380
This file contains 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
name: PR actions | |
on: | |
issue_comment: | |
types: [created, edited] | |
jobs: | |
publish: | |
name: Publish PR packages | |
runs-on: ubuntu-latest | |
if: github.event.issue.pull_request && contains(github.event.comment.body, '/publish') | |
permissions: | |
id-token: write | |
pull-requests: write | |
contents: write | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: ${{ format('refs/pull/{0}/head', github.event.issue.number) }} | |
path: app-frontend | |
fetch-depth: 0 | |
- name: install node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
- name: Git author config | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
- name: Build PR release version | |
id: build-version | |
working-directory: app-frontend | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
sha=$(gh pr view ${{ github.event.issue.number }} --repo ${{ github.repository }} --json headRefOid | jq -r '.headRefOid' | cut -c1-8) | |
branch=$(gh pr view ${{ github.event.issue.number }} --repo ${{ github.repository }} --json headRefName | jq -r '.headRefName' | sed 's/.*\///') | |
version=$(git describe --abbrev=0 --tags 2>/dev/null) | |
version=$(echo $version | cut -d '-' -f 1) | |
version="$version-pr.${{ github.run_number }}.$branch.$sha" | |
versionWithoutPrefix=$(echo $version | sed 's/^v//') | |
git tag -a $version -m "PR release $version" | |
echo "PR_RELEASE_VERSION=$version" >> $GITHUB_ENV | |
echo "PR_RELEASE_VERSION=$versionWithoutPrefix" >> $GITHUB_OUTPUT | |
echo $version | |
- name: Create PR comment | |
uses: peter-evans/create-or-update-comment@v4 | |
id: pr-comment | |
with: | |
issue-number: ${{ github.event.issue.number }} | |
body: | | |
## PR release: | |
* `<link rel="stylesheet" type="text/css" href="https://altinncdn.no/toolkits/altinn-app-frontend/${{ steps.build-version.outputs.PR_RELEASE_VERSION }}/altinn-app-frontend.css">` | |
* `<script src="https://altinncdn.no/toolkits/altinn-app-frontend/${{ steps.build-version.outputs.PR_RELEASE_VERSION }}/altinn-app-frontend.js"></script>` | |
> ⚙️ Building... | |
- name: install dependencies | |
working-directory: app-frontend | |
run: yarn --immutable | |
- name: run build | |
working-directory: app-frontend | |
run: yarn build | |
- name: Checkout Altinn-CDN repository | |
uses: actions/checkout@v4 | |
if: '!env.ACT' | |
with: | |
repository: 'Altinn/altinn-cdn' | |
token: ${{secrets.ALTINN_CDN_TOKEN}} | |
path: cdn | |
- name: Azure login | |
uses: azure/login@v2 | |
if: '!env.ACT' | |
with: | |
client-id: ${{ secrets.AZURE_CLIENT_ID_FC }} | |
tenant-id: ${{ secrets.AZURE_TENANT_ID_FC }} | |
subscription-id: ${{ secrets.AZURE_CDN_SUBSCRIPTION_ID_FC }} | |
- name: Run release script (pre-release) | |
working-directory: app-frontend | |
if: '!env.ACT' | |
env: | |
FD_DOMAIN: ${{ vars.AZURE_DOMAIN_FC }} | |
FD_ENDPOINT: ${{ vars.AZURE_ENDPOINT_FC }} | |
FD_PROFILE: ${{ vars.AZURE_PROFILE_FC }} | |
FD_RESOURCEGROUP: ${{ vars.AZURE_RESOURCE_GROUP_FC }} | |
run: | | |
bash .github/scripts/release.sh \ | |
--frontend . \ | |
--cdn ../cdn \ | |
--commit \ | |
--pre-release \ | |
--azure-sync-cdn \ | |
--azure-sa-name "${{ secrets.PRODUCTION_STORAGEACCOUNT_NAME }}" \ | |
--azure-sa-token "${{ secrets.PRODUCTION_ALTINN_CDN_SAS_TOKEN }}" | |
- name: Push to CDN | |
working-directory: cdn | |
if: '!env.ACT' | |
run: git push | |
- name: Update PR comment - failure | |
uses: peter-evans/create-or-update-comment@v4 | |
if: failure() | |
with: | |
issue-number: ${{ github.event.issue.number }} | |
comment-id: ${{ steps.pr-comment.outputs.comment-id }} | |
edit-mode: append | |
body: | | |
> ❌ Failed: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} | |
- name: Update PR comment - success | |
uses: peter-evans/create-or-update-comment@v4 | |
if: success() | |
with: | |
issue-number: ${{ github.event.issue.number }} | |
comment-id: ${{ steps.pr-comment.outputs.comment-id }} | |
edit-mode: append | |
body: | | |
> ✅ Done! | |
reactions: rocket |