Skip to content

Integration Tests

Integration Tests #112

name: Integration Tests
on:
workflow_dispatch:
workflow_run:
workflows: ['CI']
branches:
- main
- 'releases/*'
types:
- completed
schedule:
- cron: '0 22 * * 3'
permissions:
contents: read
jobs:
integration-tests:
name: Integration Test
runs-on: ubuntu-latest
permissions:
contents: write
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }}
steps:
- name: Checkout
id: checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Make note of the branch name
id: branch-name
run: echo "BRANCH=$(git rev-parse --abbrev-ref HEAD)" >> "$GITHUB_OUTPUT"
- name: Generate GitHub App Token
uses: electron/github-app-auth-action@384fd19694fe7b6dcc9a684746c6976ad78228ae # v1.1.1
id: generate-token
with:
creds: ${{ secrets.GH_APP_CREDS }}
- name: Make changes to commit and stage them
run: |
date > current-date.txt
echo 'foobar' > README.md
curl -o git-logo.png https://git-scm.com/images/logos/downloads/Git-Icon-1788C.png
GIT_LOGO_SHA=$(git hash-object -t blob git-logo.png)
mv git-logo.png "git-logo-${GIT_LOGO_SHA}.png"
git add current-date.txt
git add README.md
git rm LICENSE
git add --chmod=+x src/lib.ts
git add "git-logo-${GIT_LOGO_SHA}.png"
- name: Commit to new ref
uses: ./
id: commit-new-ref
with:
message: Test new ref commit
ref: integration-test-playground-${{ github.run_id }}-${{ github.run_number }}
token: ${{ steps.generate-token.outputs.token }}
- name: Confirm new ref commit
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
github-token: ${{ steps.generate-token.outputs.token }}
script: |
const assert = require('node:assert');
const message = 'Test new ref commit';
const refs = ['integration-test-playground-${{ github.run_id }}-${{ github.run_number }}', '${{ steps.commit-new-ref.outputs.sha }}'];
// Fetch the commit by both ref and sha
for (const ref of refs) {
const { data } = await github.rest.repos.getCommit({
owner: context.repo.owner,
repo: context.repo.repo,
ref,
});
assert.strictEqual('${{ steps.commit-new-ref.outputs.message }}', message, 'Expected correct message output');
assert.strictEqual('${{ steps.commit-new-ref.outputs.ref }}', refs[0], 'Expected correct ref output');
assert.strictEqual('${{ steps.commit-new-ref.outputs.ref-operation }}', 'created', 'Expected correct ref operation');
assert.strictEqual(data.sha, '${{ steps.commit-new-ref.outputs.sha }}', 'Expected sha for commit to match');
assert.strictEqual(data.commit.message, message, 'Expected commit message to match');
assert.strictEqual(data.commit.verification.verified, true, 'Expected commit to be verified');
const { data: { tree } } = await github.rest.git.getTree({
owner: context.repo.owner,
repo: context.repo.repo,
tree_sha: ref,
});
const filenameRegex = /git-logo-(\S+).png/;
const { path, sha } = tree.find(({ path }) => filenameRegex.test(path));
const [, expectedSha] = path.match(filenameRegex);
assert.strictEqual(sha, expectedSha, 'Expected SHA for Git logo PNG to match');
}
- name: Update checkout
run: |
git fetch
git checkout integration-test-playground-${{ github.run_id }}-${{ github.run_number }}
- name: Make changes to commit and stage them
run: |
date > current-date.txt
echo 'baz' > README.md
git add current-date.txt
git add README.md
git rm .prettierignore
git add --chmod=+x src/main.ts
- name: Update existing ref
uses: ./
id: update-existing-ref
with:
message: Test updating existing ref
ref: integration-test-playground-${{ github.run_id }}-${{ github.run_number }}
token: ${{ steps.generate-token.outputs.token }}
- name: Confirm existing ref commit
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
github-token: ${{ steps.generate-token.outputs.token }}
script: |
const assert = require('node:assert');
const message = 'Test updating existing ref';
const refs = ['integration-test-playground-${{ github.run_id }}-${{ github.run_number }}', '${{ steps.update-existing-ref.outputs.sha }}'];
// Fetch the commit by both ref and sha
for (const ref of refs) {
const { data } = await github.rest.repos.getCommit({
owner: context.repo.owner,
repo: context.repo.repo,
ref,
});
assert.strictEqual('${{ steps.update-existing-ref.outputs.message }}', message, 'Expected correct message output');
assert.strictEqual('${{ steps.update-existing-ref.outputs.ref }}', refs[0], 'Expected correct ref output');
assert.strictEqual('${{ steps.update-existing-ref.outputs.ref-operation }}', 'updated', 'Expected correct ref operation');
assert.strictEqual(data.sha, '${{ steps.update-existing-ref.outputs.sha }}', 'Expected sha for commit to match');
assert.strictEqual(data.commit.message, message, 'Expected commit message to match');
assert.strictEqual(data.commit.verification.verified, true, 'Expected commit to be verified');
}
- name: Update checkout
run: git pull
- name: Make more changes to commit and stage them
run: |
date > current-date.txt
git add current-date.txt
- name: Update existing ref (again)
uses: ./
id: update-existing-ref-2
with:
message: Test updating existing ref (again)
ref: integration-test-playground-${{ github.run_id }}-${{ github.run_number }}
token: ${{ steps.generate-token.outputs.token }}
- name: Confirm existing ref commit
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
github-token: ${{ steps.generate-token.outputs.token }}
script: |
const assert = require('node:assert');
const message = 'Test updating existing ref (again)';
const refs = ['integration-test-playground-${{ github.run_id }}-${{ github.run_number }}', '${{ steps.update-existing-ref-2.outputs.sha }}'];
// Fetch the commit by both ref and sha
for (const ref of refs) {
const { data } = await github.rest.repos.getCommit({
owner: context.repo.owner,
repo: context.repo.repo,
ref,
});
assert.strictEqual('${{ steps.update-existing-ref-2.outputs.message }}', message, 'Expected correct message output');
assert.strictEqual('${{ steps.update-existing-ref-2.outputs.ref }}', refs[0], 'Expected correct ref output');
assert.strictEqual('${{ steps.update-existing-ref-2.outputs.ref-operation }}', 'updated', 'Expected correct ref operation');
assert.strictEqual(data.sha, '${{ steps.update-existing-ref-2.outputs.sha }}', 'Expected sha for commit to match');
assert.strictEqual(data.commit.message, message, 'Expected commit message to match');
assert.strictEqual(data.commit.verification.verified, true, 'Expected commit to be verified');
}
- name: Update checkout
run: |
git pull
git clean -fdx
git restore .
- name: Optionally don't fail if no changes to commit
uses: ./
with:
fail-on-no-changes: false
message: Nothing to commit
ref: integration-test-playground-${{ github.run_id }}-${{ github.run_number }}
token: ${{ steps.generate-token.outputs.token }}
- name: Switch back to base branch
run: git switch ${{ steps.branch-name.outputs.BRANCH }}
- name: Make changes to commit and stage them
run: |
date +%s%3N > current-date.txt
git add current-date.txt
- name: Update existing ref (force)
uses: ./
id: force-update-existing-ref
with:
force: true
message: Test updating existing ref (force)
ref: integration-test-playground-${{ github.run_id }}-${{ github.run_number }}
token: ${{ steps.generate-token.outputs.token }}
- name: Confirm forced commit
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
github-token: ${{ steps.generate-token.outputs.token }}
script: |
const assert = require('node:assert');
const message = 'Test updating existing ref (force)';
const refs = ['integration-test-playground-${{ github.run_id }}-${{ github.run_number }}', '${{ steps.force-update-existing-ref.outputs.sha }}'];
// Fetch the commit by both ref and sha
for (const ref of refs) {
const { data } = await github.rest.repos.getCommit({
owner: context.repo.owner,
repo: context.repo.repo,
ref,
});
assert.strictEqual('${{ steps.force-update-existing-ref.outputs.message }}', message, 'Expected correct message output');
assert.strictEqual('${{ steps.force-update-existing-ref.outputs.ref }}', refs[0], 'Expected correct ref output');
assert.strictEqual('${{ steps.force-update-existing-ref.outputs.ref-operation }}', 'updated', 'Expected correct ref operation');
assert.strictEqual(data.sha, '${{ steps.force-update-existing-ref.outputs.sha }}', 'Expected sha for commit to match');
assert.strictEqual(data.commit.message, message, 'Expected commit message to match');
assert.strictEqual(data.commit.verification.verified, true, 'Expected commit to be verified');
}
- name: Clean up new ref
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
if: ${{ always() && steps.generate-token.outputs.token }}
with:
github-token: ${{ steps.generate-token.outputs.token }}
script: |
await github.rest.git.deleteRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'heads/integration-test-playground-${{ github.run_id }}-${{ github.run_number }}'
});